<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of NetworkController
 *
 * @author mateusz.ledzewicz
 */
class InstrumentController extends FormListController {
    protected function begin() {
        $this->view = new ViewInstrument();
        
    }

    protected function listRun(){
        $this->view->setSpecialVar('list', Instrument::getAll());
        $this->view->setModel(Instrument::loadModel(), 'header'); 
    }
    
    protected function formRun(){
        $id = (isSet($_GET['id']) && !empty($_GET['id'])) ? $_GET['id'] : null;
        $model = Instrument::loadModel($id);
        
        if(count($_POST) > 0){
            
            $model->setValues($_POST);
            
            if($model->NewRecord && Instrument::loadSpecialModel("name = '{$model->name}' ")->NewRecord == FALSE)
            {
                throw new Exception('Network with this name exists');
            }
            $model->save();
            header("Location: index.php?step=instrument");
       
       }
       $this->view->setModel($model, 'edit');
    }


        
        
        //put your code here
}

?>
